package leetcode;

import java.util.Map;
import java.util.TreeMap;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 打印出一个字符串中各个字符出现的次数
 *
 * @author 王霄
 * @date 2022/2/13 20:09
 */
public class Code002 {
    public static void main(String[] args) {
        print("bf83g4ng9e4hg439h2jh409hbjwpmbdfpokhq35hkw45jkejh[34jh3[5ih42inh2pi5inh3j4hj95h95h9j54h96");
    }

    public static void print(String s) {
        Map<Character, Long> map = IntStream.range(0, s.length())
                .mapToObj(s::charAt)
                .collect(Collectors.groupingBy(Function.identity(), TreeMap::new, Collectors.counting()));
        System.out.println(map);
    }
}
